﻿package client;
import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTabbedPane;
import java.awt.GridBagLayout;
import javax.swing.JRadioButton;
import java.awt.GridBagConstraints;
import java.awt.Insets;

import javax.swing.BorderFactory;
import javax.swing.DefaultListModel;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;
import javax.swing.JList;
import javax.swing.AbstractListModel;
import javax.swing.ListSelectionModel;
import java.awt.Font;
import javax.swing.ImageIcon;

import java.rmi.*;
import java.rmi.server.*;
import server.ResMenuInterface;
import server.ResMenuList;
import server.ResWaiterInterface;

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.List;
import java.util.Vector;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import client.Configuration;
import java.awt.Color;

public class ResMenuGUI extends JDialog {

	private JPanel contentPane;
	
	// private DefaultListModel listModel;
//	 private DefaultListModel listModel1;
	// private DefaultListModel listModel2;


	private int kind;
	private int num;
	Vector<String> v;
	Vector<String> v1;
	Vector<String> v2;
	
	Vector<String> v3;
	Vector<String> v5;

/**Launch the application.
	
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
//		    		ResMenuInterface menu = (ResMenuInterface) Naming.lookup("Hello");    
					ResMenuGUI frame = new ResMenuGUI();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	
	}
	
	 * 	
	
 */


	

	/**
	 * Create the frame.
	 * @throws NotBoundException 
	 * @throws RemoteException 
	 * @throws MalformedURLException 
	 */
	public ResMenuGUI(int Kind,int number) throws MalformedURLException, RemoteException, NotBoundException {
		
		kind=Kind;
		num=number;
		
		setTitle("\u83DC\u5355");
		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 781, 551);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		final JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		tabbedPane.setForeground(new Color(128, 128, 128));
		tabbedPane.setFont(new Font("方正卡通简体", Font.BOLD, 18));
		tabbedPane.setBounds(58, 23, 316, 395);
		contentPane.add(tabbedPane);
		
try{
		

		Configuration config= new Configuration();

		String rmiAddress=config.getRmiAddress();
		ResMenuInterface menu = (ResMenuInterface) Naming.lookup(rmiAddress+"ResMenuList");





JScrollPane scrollPane_1 = new JScrollPane();
tabbedPane.addTab("热菜", null, scrollPane_1, null);


v=new Vector<String>();
v1=new Vector<String>();
v2=new Vector<String>();
v3=new Vector<String>();
v5=new Vector<String>();



		for(int i=1;i<=menu.getMenuSize(1);i++)
{
		String a1=Double.toString(menu.getPrice(i));
		String a2=Double.toString(menu.getHp(i));
		v1.addElement(menu.getName(i)+"    "+a1+"    "+a2);
		v.addElement(menu.getName(i)+"    "+a1+"    "+a2);
		v5.addElement(menu.getName(i));
}

for(int i=menu.getMenuSize(1)+1;i<=menu.getMenuSize(2)+menu.getMenuSize(1);i++)
{
	String a1=Double.toString(menu.getPrice(i));
	String a2=Double.toString(menu.getHp(i));
	v2.addElement(menu.getName(i)+"    "+a1+"    "+a2);
	v.addElement(menu.getName(i)+"    "+a1+"    "+a2);
	v5.addElement(menu.getName(i));
}

for(int i=1+menu.getMenuSize(2)+menu.getMenuSize(1);i<=menu.getMenuSize(3)+menu.getMenuSize(2)+menu.getMenuSize(1);i++)
{
	String a1=Double.toString(menu.getPrice(i));
	String a2=Double.toString(menu.getHp(i));
	v3.addElement(menu.getName(i)+"    "+a1+"    "+a2);
	v.addElement(menu.getName(i)+"    "+a1+"    "+a2);
	v5.addElement(menu.getName(i));
}






final JList list = new JList(v1);
list.setForeground(new Color(128, 128, 128));
list.setFont(new Font("华文行楷", Font.PLAIN, 18));
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
scrollPane_1.setViewportView(list);

JScrollPane scrollPane_2 = new JScrollPane();

tabbedPane.addTab("冷菜", null, scrollPane_2, null);


final JList list_1 = new JList(v2);
list_1.setFont(new Font("华文行楷", Font.PLAIN, 18));
list_1.setForeground(new Color(128, 128, 128));
scrollPane_2.setViewportView(list_1);

final JScrollPane scrollPane = new JScrollPane();

tabbedPane.addTab("主食、粥", null, scrollPane, null);

final JList list_2 = new JList(v3);
list_2.setForeground(new Color(128, 128, 128));
list_2.setFont(new Font("华文行楷", Font.PLAIN, 18));
scrollPane.setViewportView(list_2);

final JScrollPane scrollPane_3 = new JScrollPane();
scrollPane_3.setBounds(411, 49, 300, 369);
contentPane.add(scrollPane_3);



final Vector<String> v4=new Vector<String>();


			
final JList list_3 = new JList(v4);
list_3.setFont(new Font("华文行楷", Font.PLAIN, 18));
list_3.setForeground(new Color(128, 128, 128));
scrollPane_3.setViewportView(list_3);	


			
JButton button = new JButton("\u589E\u52A0");
button.setForeground(new Color(128, 128, 128));
button.setFont(new Font("方正卡通简体", Font.PLAIN, 18));
button.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e) {

			if(tabbedPane.getSelectedComponent() != null){
				int i=tabbedPane.getSelectedIndex();
			
			if(i==0&&list.getSelectedIndex()!=-1){
				v4.addElement((String) list.getSelectedValue());
			}
			if(i==1&&list_1.getSelectedIndex()!=-1){
			
				v4.addElement((String) list_1.getSelectedValue());

			}
			if(i==2&&list_2.getSelectedIndex()!=-1){
				v4.addElement((String) list_2.getSelectedValue());

			}
		
			list_3.setListData(v4);
			}
		}
});
		

		

button.setBounds(176, 428, 93, 23);
contentPane.add(button);



JButton button_1 = new JButton("\u5220\u9664");
button_1.setForeground(new Color(128, 128, 128));
button_1.setFont(new Font("方正卡通简体", Font.PLAIN, 18));
button_1.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e) {
			if(list_3.getSelectedIndex()!=-1){
				v4.remove((String) list_3.getSelectedValue());
				list_3.setListData(v4);

			}
			else
				JOptionPane.showMessageDialog(null, "error  error");
				
		}
});
button_1.setBounds(525, 428, 93, 23);
contentPane.add(button_1);





JButton button_2 = new JButton("\u63D0\u4EA4\u83DC\u5355");
button_2.setForeground(new Color(60, 179, 113));
button_2.setFont(new Font("方正卡通简体", Font.PLAIN, 18));
button_2.setBounds(337, 480, 119, 23);
contentPane.add(button_2);








button_2.addActionListener(new ActionListener() {
	public void actionPerformed(ActionEvent e) {
	
        int a[]=new int[v4.size()];
        int i=0;
        String orderlist=new String("");
		for(String ob:v4){
			a[i]= v.indexOf(ob)+1;
			i++;
		}
		//ResWaiterInterface waiter = (ResWaiterInterface) Naming.lookup(rmiAddress+"ResWaiter");


		for(int j=0;j<v4.size(); j++){
	
			String dish=v5.get(a[j]-1);
			orderlist=orderlist+dish+"\n";
		}
       
		dispose();
		
		ResOrderListGUI orderList=new ResOrderListGUI(orderlist,a,kind,num);
		orderList.setModal(true);
		orderList.setLocationRelativeTo(null);
		orderList.setVisible(true);
		
			
	}
});



///////////////////
//////////////
////////







JLabel label = new JLabel("\u60A8\u70B9\u7684\u83DC\uFF1A");
label.setForeground(new Color(192, 192, 192));
label.setFont(new Font("方正卡通简体", Font.BOLD, 18));
label.setBounds(424, 23, 145, 21);
contentPane.add(label);
JLabel lblNewLabel = new JLabel("New label");
lblNewLabel.setForeground(new Color(154, 205, 50));
lblNewLabel.setIcon(new ImageIcon("src/client/images/ae640efd91cc66dafc037fc5.jpg"));
lblNewLabel.setBounds(0, 0, 765, 513);
contentPane.add(lblNewLabel);

} catch (Exception e1) {
	// TODO Auto-generated catch block
	e1.printStackTrace();
}
	
}
	}
